package com.ayou.eggguard.farm.controller;

import com.ayou.common.utils.PageBean;
import com.ayou.common.utils.Result;
import com.ayou.eggguard.farm.pojo.WarningConfig;
import com.ayou.eggguard.farm.service.WarningConfigService;
import jakarta.annotation.Priority;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/warningConfig")
public class WarningConfigController {

    @Autowired
    private WarningConfigService warningConfigService;

    @GetMapping("/list")
    public Result<PageBean<WarningConfig>> getConfigList(Integer pageNum,
                                                         Integer pageSize,
                                                         @RequestParam(required = false) String warningType){
        PageBean<WarningConfig> pb=warningConfigService.getConfigList(pageNum,pageSize,warningType);
        return Result.success(pb);
    }

    @PostMapping("/add")
    public Result add(@RequestBody WarningConfig warningConfig){
        if(warningConfigService.getConfigByName(warningConfig.getWarningType())!=null){
            return Result.error("预警类型已存在");
        }else{
            warningConfigService.add(warningConfig);
            return Result.success();
        }

    }
}
